package ldh.im.admin.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.atomic.AtomicInteger;

@Component
public class LogInterceptor implements HandlerInterceptor {

    private static final Logger LOGGER = LoggerFactory.getLogger(LogInterceptor.class);
    private static final AtomicInteger atomicInteger = new AtomicInteger(1);


    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        int value = atomicInteger.incrementAndGet();
//        if (value % 2 == 0) {
//            throw new RuntimeException(String.format("value is %s", value));
//        }
        LOGGER.info("{} request {}", request.getRequestURI(), request.getMethod());
        return true;
    }
}
